package com.sphd.restaurantsystem.model;


import com.android.volley.VolleyError;
import com.sphd.restaurantsystem.info.ApplyForInfo;
import com.sphd.restaurantsystem.interfaces.VolleyJsonObjectCallBack;
import com.sphd.restaurantsystem.presenter.ApplyForPresenterImpl;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
* Created by Hu on 2017/01/04
*/

public class ApplyForModelImpl implements ApplyForModel {

    @Override
    public void addPerRecord(String url, ApplyForPresenterImpl applyForPresenter) {
        volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    List<ApplyForInfo> applyForInfos = JsonUtil.getListFromString(response.getString("list"),ApplyForInfo.class);
                    applyForPresenter.sendPersonRecord(applyForInfos);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
            applyForPresenter.sendError(error);
            }
        });
    }

    @Override
    public void setSureMoney(String url, ApplyForPresenterImpl applyForPresenter) {
        volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    int res =response.getInt("res");
                    applyForPresenter.recRes(res);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                applyForPresenter.sendError(error);
            }
        });
    }
}